/*************************************************************************
	> File Name: append.c
	> Author: Angel Criss
	> Mail: abbytsing@gmail.com 
	> Created Time: Fri 14 Mar 2014 09:29:33 AM CST
 ************************************************************************/

#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(int argc, char * argv[])
{
    int fileo, filew;
    char buf[100];
    int len=100,i;

    for(i=0;i<100;i++)
        buf[i]=i;
 if(argc=2)
 {
    fileo=open(argv[1],O_RDWR|O_APPEND);//O_APPEND 原子操作
    if(fileo==-1)
        printf("cannot open file\n");
    else
        printf("file opened\n");
    lseek(fileo,0,SEEK_SET);

    filew=write(fileo,buf,len);
    if(filew==-1)
        printf("cannot write\n");
    else
        printf("file writed\n");
 }
}
